package com.jyw.business.ins.controller;

import com.github.pagehelper.PageHelper;
import com.jyw.business.ast.domain.dto.web.InsTaskAstPageDto;
import com.jyw.business.ast.domain.vo.web.InsTaskAstPageVo;
import com.jyw.business.ins.domain.dto.web.InsTaskEditDto;
import com.jyw.business.ins.domain.dto.web.InsTransmitRecordAddDto;
import com.jyw.business.ins.domain.dto.web.TaskUnitPageDto;
import com.jyw.business.ins.domain.vo.web.InsTaskInfoVO;
import com.jyw.business.ins.domain.vo.web.TaskUnitPageVo;
import com.jyw.business.ins.service.IInsTaskService;
import com.jyw.business.ins.service.IInsTransmitRecordService;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Created by ZhangCheng on 2023/10/09
 */
@RestController
@RequestMapping("/ins/task")
@Api(tags = "巡检任务")
public class InsTaskController extends BaseController {

    @Resource
    private IInsTaskService insTaskService;

    @Resource
    private IInsTransmitRecordService insTransmitRecordService;


    /**
     * 资产查询
     */
    @PreAuthorize("@ss.hasPermi('ins:task:list')")
    @PostMapping("/ast/list")
    @ApiOperation("资产查询")
    public TableDataInfo<InsTaskAstPageVo> astList(@RequestBody InsTaskAstPageDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).reasonable(true);
        List<InsTaskAstPageVo> list = insTaskService.taskAstList(dto);
        return getDataTable(list);
    }

    /**
     * 巡检单元查询
     */
    @PreAuthorize("@ss.hasPermi('ins:task:list')")
    @PostMapping("/unit/list")
    @ApiOperation("巡检单元查询")
    public TableDataInfo<TaskUnitPageVo> unitList(@RequestBody TaskUnitPageDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).reasonable(true);
        List<TaskUnitPageVo> list = insTaskService.taskUnitList(dto);
        return getDataTable(list);
    }

    /**
     * 获取巡检任务详细信息
     */
    @ApiOperation("获取巡检任务详细信息")
    @PreAuthorize("@ss.hasPermi('inspection:task:query')")
    @GetMapping(value = "/getInfo/{id}")
    public CommonResult<InsTaskInfoVO> getInfo(@PathVariable("id") Long id) {
        InsTaskInfoVO insTaskInfo = insTaskService.getInfoById(id);
        return CommonResult.success(insTaskInfo);
    }

    /**
     * 修改巡检任务（去巡检）
     *
     * @param insTaskEditDto
     * @return
     */
    @ApiOperation("修改巡检任务（去巡检）")
    @PreAuthorize("@ss.hasPermi('inspection:task:edit')")
    @Log(title = "巡检任务转交", businessType = BusinessType.UPDATE)
    @PutMapping(value = "editTask")
    public CommonResult edit(@RequestBody @Valid InsTaskEditDto insTaskEditDto) {
        insTaskService.editInsTask(insTaskEditDto);
        return CommonResult.success();
    }

    /**
     * 巡检任务转交
     *
     * @param insTransmitRecordAddDto
     * @return
     */
    @ApiOperation("巡检任务转交")
    @PreAuthorize("@ss.hasPermi('inspection:task:transmit')")
    @Log(title = "巡检任务转交")
    @PostMapping(value = "transmit")
    public CommonResult transmit(@RequestBody @Valid InsTransmitRecordAddDto insTransmitRecordAddDto) {
        insTransmitRecordService.transmitRecord(insTransmitRecordAddDto);
        return CommonResult.success();
    }

}
